package service;

import bean.Dept;
import bean.Emp;
import mapper.DeptMapper;
import mapper.EmpMapper;

import java.io.IOException;

public class EmpService extends BaseService {
    private EmpMapper empMapper;
    private DeptMapper deptMapper;

    public EmpService() {
        try {
            empMapper = getMapper(EmpMapper.class);
            deptMapper = getMapper(DeptMapper.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //拆箱装箱
    public Emp findEmpByNo(int id){
        //只能获取到员工信息
        Emp emp=empMapper.findEmpByNo4(id);
        if(emp==null){
            return null;
        }
        //获取部门信息
        Dept dept=deptMapper.findDeptByNo(emp.getDeptNo());
        emp.setDept(dept);
        return  emp;
    }
}
